<?php include("facebook_include.php");?>
<?php
    $name = $_GET['name'];
    $description = $_GET['description'];
    $location = $_GET['location'];
    $city = $_GET['city'];
    $userName = $_GET['userName'];
    $starttime = $_GET['starttime'];
    $starttimemonth = intval(substr($starttime, 0,2));
    $starttimedate = intval(substr($starttime, 3,2));
    $starttimeyear = intval(substr($starttime, 6,4));
    $starttimehour = intval(substr($starttime, 11,2));
    $starttimemin = intval(substr($starttime, 14,2));
    
    
    $endtime = $_GET['endtime'];
    
    
    $endtimemonth = intval(substr($endtime, 0,2));
    $endtimedate = intval(substr($endtime, 3,2));
    $endtimeyear = intval(substr($endtime, 6,4));
    $endtimehour = intval(substr($endtime, 11,2));
    $endtimemin = intval(substr($endtime, 14,2));
    
?>

<?php
	    $event_info = array();
        $event_info['name'] = $name;
        $event_info['category'] = '8'; // Use valid category number
        $event_info['subcategory'] = '51'; //Use valid subcategory number
        $event_info['host'] = $userName;
        $event_info['location'] = $location;
        $event_info['city'] = $city; //Must be a valid city name
        $event_info['start_time'] = gmmktime($starttimehour,$starttimemin,00,$starttimemonth,$starttimedate,$starttimeyear); //Epoch timestamp
        $event_info['end_time'] = gmmktime($endtimehour,$endtimemin,00,$endtimemonth,$endtimedate,$endtimeyear); //Epoch timestamp
        $event_info['description'] = htmlentities($description);
	    $event_info['privacy_type'] = 'OPEN';
	    $event_id = 0;
        $event_id =$facebook->api_client->events_create(json_encode($event_info));
        $friends = getFriendsUIDInApplication();
    	$facebook->api_client->events_invite( $event_id, $friends, '');
        echo $event_id;
?>
